package org.agony2d.view.core 
{
	import flash.display.Sprite;
	import flash.geom.Point;
	import org.agony2d.core.agony_internal;
	
	use namespace agony_internal;
	
public class AgonySprite extends Sprite
{
	
	public function AgonySprite()
	{
		m_scaleX = m_scaleY = m_alpha = 1
		m_rotation = 0
	}
	
	final public function get global() : Point
	{
		m_cachedPoint.x = this.x;
		m_cachedPoint.y = this.y;
		return this.parent.localToGlobal(m_cachedPoint);
	}
	
	override public function get rotation():Number{ return m_rotation }
	override public function set rotation( v:Number ) : void 
	{
		super.rotation = m_rotation = Boolean(v % 360 < 0) ? ( v % 360 + 360 ) : ( v % 360 );
	}
	
	override public function get scaleX():Number{ return this.m_scaleX; }
	override public function set scaleX( v:Number ) : void 
	{
		super.scaleX = m_scaleX = (v < 0) ? 0 : v;
	}
	
	override public function get scaleY():Number { return this.m_scaleY; }
	override public function set scaleY( v:Number ) : void
	{ 
		super.scaleY = m_scaleY = (v < 0) ? 0 : v;
	}
	
	override public function get alpha() : Number{ return m_alpha; }
	override public function set alpha( v:Number ) : void 
	{
		super.alpha = m_alpha = v;
	}
	
	public function move( x:Number, y:Number ) : void
	{
		this.x = x;
		this.y = y;
	}	
	
	final public function moveInStage( x:Number, y:Number ) : void
	{
		var local:Point
		
		m_cachedPoint.x  =  x
		m_cachedPoint.y  =  y
		local            =  this.parent.globalToLocal(m_cachedPoint)
		this.x           =  local.x
		this.y           =  local.y
	}
	
	public function offset( tx:Number, ty:Number ) : void
	{
		this.x += tx;
		this.y += ty;
	}
	
	public function reset() : void
	{
		if (m_alpha != 1 || m_rotation != 0 || m_scaleX != 1 || m_scaleY != 1)
		{
			super.rotation = m_rotation = 0;
			super.scaleX = m_scaleX = super.scaleY = m_scaleY = super.alpha = m_alpha = 1;
		}
		this.x = this.y = 0;
	}
	
	agony_internal function dispose() : void
	{
		if (this.parent)
		{
			this.parent.removeChild(this);
		}
		this.reset()
	}
	
	agony_internal static var m_cachedPoint:Point = new Point()
	
	agony_internal var m_alpha:Number, m_scaleX:Number, m_scaleY:Number, m_rotation:Number	
}
}